package com.ehuoyun.ecstore.biz;

import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.persistence.PersistenceContext;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.jpa.JpaTemplate;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.ehuoyun.ecstore.model.User;

@Component
@Transactional
public class UserMgr {
	@Autowired
	JpaTemplate jpaTemplate;
	
	@PersistenceContext
    private EntityManager em;	
	
	public User getUser(String username) {
		try{
			return (User)em.createQuery(
					"select from com.ehuoyun.ecstore.model.User" +
					" where username= '" + username + "'")
					.getSingleResult();
		} catch (NoResultException e) {
			return null;
		}
	}
	
	public void save(User user) {
		em.persist(user);
	}
}
